package com.ruoyi.web.controller.match;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.match.domain.MatchEvaluation;
import com.ruoyi.match.service.IMatchEvaluationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价Controller
 * 
 * @author 星野漫游
 * @date 2024-06-02
 */
@Controller
@RequestMapping("/match/evaluation")
@Api("评价管理")
public class MatchEvaluationController extends BaseController
{
    private String prefix = "match/evaluation";

    @Autowired
    private IMatchEvaluationService matchEvaluationService;

    @RequiresPermissions("match:evaluation:view")
    @GetMapping()
    public String evaluation()
    {
        return prefix + "/evaluation";
    }

    /**
     * 查询评价列表
     */
    @RequiresPermissions("match:evaluation:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询评价列表")
    public TableDataInfo list(MatchEvaluation matchEvaluation)
    {
        startPage();
        List<MatchEvaluation> list = matchEvaluationService.selectMatchEvaluationList(matchEvaluation);
        return getDataTable(list);
    }

    /**
     * 导出评价列表
     */
    @RequiresPermissions("match:evaluation:export")
    @Log(title = "评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出评价列表")
    public AjaxResult export(MatchEvaluation matchEvaluation)
    {
        List<MatchEvaluation> list = matchEvaluationService.selectMatchEvaluationList(matchEvaluation);
        ExcelUtil<MatchEvaluation> util = new ExcelUtil<MatchEvaluation>(MatchEvaluation.class);
        return util.exportExcel(list, "评价数据");
    }

    /**
     * 新增评价
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评价
     */
    @RequiresPermissions("match:evaluation:add")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MatchEvaluation matchEvaluation)
    {
        return toAjax(matchEvaluationService.insertMatchEvaluation(matchEvaluation));
    }

    /**
     * 修改评价
     */
    @RequiresPermissions("match:evaluation:edit")
    @GetMapping("/edit/{evaluationId}")
    public String edit(@PathVariable("evaluationId") Long evaluationId, ModelMap mmap)
    {
        MatchEvaluation matchEvaluation = matchEvaluationService.selectMatchEvaluationByEvaluationId(evaluationId);
        mmap.put("matchEvaluation", matchEvaluation);
        return prefix + "/edit";
    }

    /**
     * 修改保存评价
     */
    @RequiresPermissions("match:evaluation:edit")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MatchEvaluation matchEvaluation)
    {
        return toAjax(matchEvaluationService.updateMatchEvaluation(matchEvaluation));
    }

    /**
     * 删除评价
     */
    @RequiresPermissions("match:evaluation:remove")
    @Log(title = "评价", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(matchEvaluationService.deleteMatchEvaluationByEvaluationIds(ids));
    }
}
